package org.example.Thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:Lenovo
 * Date:2022-04-09
 * Time:14:43
 */
public class Demo19 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);
        java.lang.Thread t1 = new java.lang.Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                num.getAndIncrement();
            }
        });
        java.lang.Thread t2 = new java.lang.Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                num.getAndIncrement();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        //通过get方法得到原子类内部的数值
        System.out.println(num.get());
    }
}
